<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统安全审计 - 智能水表抄表系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
        integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="/static/styles/style.css">
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
        <div class="container">
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/"><i class="fas fa-home"></i> 首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/history"><i class="fas fa-history"></i> 历史记录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/bills"><i class="fas fa-file-invoice-dollar"></i> 账单管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/anomalies"><i class="fas fa-exclamation-triangle"></i> 异常记录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/water_plans"><i class="fas fa-project-diagram"></i> 水务规划</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="/admin"><i class="fas fa-user-shield"></i> 管理控制台</a>
                    </li>
                </ul>
                <div class="navbar-nav">
                    <span class="nav-item nav-link">
                        <i class="fas fa-user"></i> {{ user.username }}
                    </span>
                    <a class="nav-link" href="/profile"><i class="fas fa-user-cog"></i> 个人中心</a>
                    <a class="nav-link" href="/logout"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
                </div>
            </div>
        </div>
    </nav>

    <div class="container py-4">
        <div class="row mb-4">
            <div class="col-md-12">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="/admin">管理控制台</a></li>
                        <li class="breadcrumb-item active" aria-current="page">系统安全审计</li>
                    </ol>
                </nav>
                <div class="d-flex justify-content-between align-items-center">
                    <h2><i class="fas fa-shield-alt"></i> 系统安全审计</h2>
                    <a href="/admin" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> 返回管理控制台
                    </a>
                </div>
            </div>
        </div>

        <div class="row mb-4">
            <div class="col-md-3 mb-4">
                <div class="card bg-primary text-white">
                    <div class="card-body text-center">
                        <i class="fas fa-sign-in-alt fa-3x mb-3"></i>
                        <h3>{{ logs|selectattr('action', 'equalto', '登录')|list|length }}</h3>
                        <p>登录操作</p>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-4">
                <div class="card bg-success text-white">
                    <div class="card-body text-center">
                        <i class="fas fa-check-circle fa-3x mb-3"></i>
                        <h3>{{ logs|selectattr('status', 'equalto', '成功')|list|length }}</h3>
                        <p>成功操作</p>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-4">
                <div class="card bg-danger text-white">
                    <div class="card-body text-center">
                        <i class="fas fa-times-circle fa-3x mb-3"></i>
                        <h3>{{ logs|selectattr('status', 'equalto', '失败')|list|length }}</h3>
                        <p>失败操作</p>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-4">
                <div class="card bg-info text-white">
                    <div class="card-body text-center">
                        <i class="fas fa-users fa-3x mb-3"></i>
                        <h3>{{ logs|map(attribute='username')|unique|list|length }}</h3>
                        <p>活跃用户</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="card shadow-sm mb-4">
            <div class="card-header bg-light">
                <h3 class="card-title mb-0"><i class="fas fa-list"></i> 审计日志记录</h3>
            </div>
            <div class="card-body">
                {% if logs %}
                <div class="table-container">
                    <table class="custom-table">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户</th>
                                <th>操作</th>
                                <th>状态</th>
                                <th>时间</th>
                                <th>详细信息</th>
                                <th>IP地址</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for log in logs %}
                            <tr class="{% if log.status == '失败' %}table-danger{% elif log.status == '成功' %}table-success{% endif %}">
                                <td>{{ log.id }}</td>
                                <td>{{ log.username }}</td>
                                <td>{{ log.action }}</td>
                                <td>
                                    {% if log.status == '成功' %}
                                    <span class="badge bg-success">成功</span>
                                    {% elif log.status == '失败' %}
                                    <span class="badge bg-danger">失败</span>
                                    {% else %}
                                    <span class="badge bg-secondary">{{ log.status }}</span>
                                    {% endif %}
                                </td>
                                <td>{{ log.action_time }}</td>
                                <td>{{ log.details }}</td>
                                <td>{{ log.ip_address if log.ip_address else '-' }}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <div class="alert alert-info">
                    <i class="fas fa-info-circle"></i> 暂无审计日志记录
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <footer class="footer">
        <div class="container">
            <p>&copy; 2023 智能水表抄表系统 | 提供水表读数和编码识别</p>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
        crossorigin="anonymous"></script>
</body>

</html> 